IF OBJECT_ID(N'ChangePassword', N'P') IS NULL
BEGIN
    EXEC (
             'CREATE PROCEDURE [dbo].[ChangePassword] AS BEGIN SELECT 1 END'
         )
END
GO

ALTER PROCEDURE ChangePassword(
    @UserName        NVARCHAR(30),
    @OldPassword     NVARCHAR(30),
    @NewPassword     NVARCHAR(30)
)
AS
BEGIN
	DECLARE @OldPasswordInDb NVARCHAR(30)
	SELECT TOP 1 @OldPasswordInDb = u.[Password]
	FROM   Users u
	WHERE  u.Username = @UserName
	
	IF (@OldPassword = @OldPasswordInDb)
	BEGIN
	    UPDATE Users
	    SET    [Password]     = @NewPassword
	    WHERE  Username       = @UserName
	           
	    RETURN @@ROWCOUNT
	END
END
GO